<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;
use app\common\Redis;
use app\common\MemcacheOperate;
//后台模块方法
class Common extends Controller
{
    public $redis;
    public $mem;
    //当任何函数加载时候  会调用此函数
    public function _initialize(){
        $this->mem=MemcacheOperate::getInstance();
        $this->redis=Redis::getRedisInstance()->getRedisConn();
        //导航栏
        $nav_cate=DB::name('category')->where('is_nav',1)->where('status',1)->order('displayorder desc')->select();
        $this->assign('nav_cate',$nav_cate);

        $record=input('record');
        if(!isset($record)){
            $record=0;
        }
        $this->assign('record',$record);
    }

    //获取用户ip地址
    public function get_real_ip(){
        $ip=false;
        if(!empty($_SERVER['HTTP_CLIENT_IP'])){
            $ip=$_SERVER['HTTP_CLIENT_IP'];
        }
        if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
            $ips=explode (', ', $_SERVER['HTTP_X_FORWARDED_FOR']);
            if($ip){ array_unshift($ips, $ip); $ip=FALSE; }
            for ($i=0; $i < count($ips); $i++){
                if(!eregi ('^(10│172.16│192.168).', $ips[$i])){
                    $ip=$ips[$i];
                    break;
                }
            }
        }
        return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
    }

}
